package com.lgl.controller;

import com.lgl.entity.ResponseResult;
import com.lgl.entity.User;
import com.lgl.enums.AppHttpCodeEnum;
import com.lgl.exception.SystemException;
import com.lgl.service.BlogLoginService;
import com.lgl.vo.BlogLoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BlogLoginController {
    @Autowired
    private BlogLoginService loginService;
    @PostMapping("/login")
    public ResponseResult login(@RequestBody BlogLoginVo user){
        if (!StringUtils.hasText(user.getUserName())){
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return loginService.login(user);
    }
    @PostMapping("/logout")
    public ResponseResult logOut(){
       return loginService.logOut();
    }
}
